package com.inlycat.web.handler;

import java.io.IOException;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;

import org.springframework.validation.BindException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;

/**
 * @author jarvan4dev@163.com
 * @since 2015年9月2日下午3:14:08
 * @category
  
 **/

@ControllerAdvice
public class GlobalExceptionHandler {

	@ExceptionHandler(SQLException.class)
	public Map<String, Object> handlerSQLException(SQLException sqlException) {

		Map<String, Object> resultMap = new HashMap<String, Object>();

		resultMap.put("code", 0);
		resultMap.put("message", "数据库异常错误");

		return resultMap;
	}

	@ExceptionHandler(IOException.class)
	public Map<String, Object> handlerIOException(Exception exception) {
		
		Map<String, Object> resultMap = new HashMap<String, Object>();
		resultMap.put("code", 0);
		resultMap.put("message", "读写异常");
		return resultMap;
	}

	@ExceptionHandler(BindException.class)
	public Map<String, Object> handlerBindException(BindException exception) {
		
		Map<String, Object> resultMap = new HashMap<String, Object>();
		resultMap.put("code", 0);
		resultMap.put("message", "请输入正确的参数");
		return resultMap;
	}

}
